{extend name="base" /}
{block name="title"}他人代录{/block}
{block name="static"}
<link rel="stylesheet" type="text/css" media="screen" href="/static/pc/css/select.css"/>
{/block}
{block name="bread"}
<div class="bread-cram">
  <div class="bread-cram-inner">
    <span class="title">保险公司使用</span>
    <span class="sub-title">- 他人代录</span>
  </div>
</div>
{/block}

{block name="main"}

          <div class="menu-content left">
            <div class="menu-content-title"><p>请他人代录资料</p></div>
            <div class="form-box" style="margin-top:35px;">
              <div class="form-content" id="addHtml">
                <div class="form-item">
                  <label>保单号：</label>
                  <input type="text" placeholder="请填写保单号"  name="report_num" onkeyup="value=value.replace(/[\u4e00-\u9fa5]/ig,'')"/>
                </div>
                <div class="form-item">
                  <label>报案号：</label>
                  <input type="text" placeholder="请填写报案号"  name="policy_num" onkeyup="value=value.replace(/[\u4e00-\u9fa5]/ig,'')"/>
                </div>
                <div class="form-item">
                  <label>出险险种：</label>
                  <select class="demo" multiple="multiple" placeholder="请选择险种"  >
                    {volist name="list" id="vo"}
                    <option value="{$vo.it_id}">{$vo.it_name}</option>
                    {/volist}
                  </select>
                </div>
                <div class="form-item">
                  <label>代录人：</label>
                  <input type="text" placeholder="请选择代录人" readonly="readonly" id="demoa"/>
                </div>
                <!--<div class="form-item">-->
                  <!--<label>代录人姓名:</label>-->
                  <!--<input type="text" placeholder="代录人姓名" readonly="readonly" />-->
                <!--</div>-->
                <!--<div class="form-item">-->
                  <!--<label>代录人类型:</label>-->
                  <!--<input type="text" placeholder="代录人类型" readonly="readonly" />-->
                <!--</div>-->
                <div class="form-item">
                  <label>请在:</label>
                  <input type="text" class="time"  id="test1"/> 前录入提交
                </div>
              </div>
              <div class="form-footer">
                <div class="step-btn-box"><div class="save-btn">确认</div></div>
              </div>
            </div>
          </div>
<input type="hidden" class="time" name="recordor_id"/>

{/block}


{block name="js"}
<script type='text/javascript' src='/static/pc/js/tableSelect.js' charset='utf-8'></script>
<script type="text/javascript">

    $(function() {
        $('.demo').fSelect({
            placeholder: '请选择出险险种',
            numDisplayed: 3,
            overflowText: '{n} selected',
            searchText: 'Search',
            showSearch: true
        });

        var laydate = layui.laydate;
        //常规用法
        laydate.render({
            elem: '#test1'
        });
        var tableSelect = layui.tableSelect;
        tableSelect.render({
            elem: '#demoa',	//定义输入框input对象
            checkedKey: 'recordor_id' ,//表格的唯一建值，非常重要，影响到选中状态 必填
            table: {	//定义表格参数，与LAYUI的TABLE模块一致，只是无需再定义表格elem
                url:"{:url('insurer/selectOtherList')}",
                response: {
                    statusCode: 200 //规定成功的状态码，默认：0
                },
                cols: [[
                    { type: 'radio' },
                    {field: 'username', title: '姓名', width:150},
                    {field: 'mobile', title: '手机号', width:150},
                    {field: 'recoder_name', title: '代录人类型', width:180}
                ]]
            },
            done: function (elem, data) {
                if(data.data.length>0){
                    var dataInfo=data.data[0];
                $("input[ name='recordor_id']").val(dataInfo.recordor_id);
                 var  a="<div class=\"form-item\" id=\"username\">";
                      a+="<label>代录人姓名:</label>";
                      a+="<input type=\"text\"  readonly=\"readonly\" name='dai'  value = \""+  dataInfo.username+"\" />"
                      a+="</div>";
                      a+="<div class=\"form-item\" id=\"recoder_name\">";
                      a+="<label>代录人类型:</label>";
                      a+="<input type=\"text\"  readonly=\"readonly\"  value = \""+  dataInfo.recoder_name+"\" />"
                      a+="</div>"
                if($('#addHtml').find('#username')){
                    $('#addHtml').find('#username').remove();
                    $('#addHtml').find('#recoder_name').remove();
                }
                   $('#addHtml').append(a);

            }
            }
        });
        $('.save-btn').on('click',function () {
            var policy_num = $("input[ name='policy_num']").val();
            var report_num = $("input[ name='report_num']").val();
            var recordor_id = $("input[ name='recordor_id']").val();
            var end_at = $("#test1").val();
            var insurance_type = $(".demo").val();
            if (report_num.length == 0) {
                layer.msg('请填写保单号', {icon: 2});
                return;
            }
            if (policy_num.length == 0) {
                layer.msg('请填写报案号', {icon: 2});
                return;
            }
            if (insurance_type.length ==0) {
                layer.msg('请选择出险险种', {icon: 2});
                return;
            }
            var str = '';
            for (i=0;i< insurance_type.length;i++){
                str+=insurance_type[i]+',';
            }

            if (recordor_id  == 0) {
                layer.msg('请选择代录人', {icon: 2});
                return;
            }
            if (end_at.length ==0) {
                layer.msg('请选择截止时间', {icon: 2});
                return;
            }

            $.ajax({
                type: 'POST',
                url: "{:url('insurer/otherInsurer')}",
                data: {
                    'policy_num':policy_num,
                    'report_num': report_num,
                    'insurance_type': str.substring(0,str.length-1),
                    'end_at': end_at,
                    'recordor_id': recordor_id,
                },
                dataType: 'json',
                success: function (Json) {
                    if (Json.code == 200) {
                        layer.msg('保存成功', {icon: 1});
                        location.reload();
                    } else {
                        layer.msg(Json.msg, {icon: 2});
                    }
                }
            });


        });
    })
</script>
{/block}

